﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.RenameUI {
    import flash.events.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Display.MarketUI.*;
    import flash.text.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;
    import Modules.franchise.*;

    public class RenameCell extends JPanel implements GridListCell {

        public static const STATE_PROPOSE:int = 0;
        public static const STATE_REQUEST:int = 1;
        public static const STATE_FINISH:int = 2;
        public static const EVENT_UPDATE:String = "RenameCell_Update";
        private static const BUTTON_WIDTH:int = 200;

        protected var m_state:int;
        protected var m_data:Object;
        protected var m_assetDict:Dictionary;
        protected var m_bgAsset:DisplayObject;
        protected var m_bodyTextHeading:String;
        protected var m_bodyTextSubHeading:String;
        protected var m_bodyTextFooter:String;
        protected var m_headerPanel:JPanel;
        protected var m_bodyPanel:JPanel;
        protected var m_footerPanel:JPanel;

        public function RenameCell(_arg1:Dictionary, _arg2:LayoutManager=null){
            this.m_assetDict = _arg1;
            super(new BorderLayout());
        }
        public function get item():String{
            return (this.m_data["item"]);
        }
        public function get itemName():String{
            return (this.m_data["itemName"]);
        }
        public function get itemPicUrl():String{
            return (this.m_data["itemPicUrl"]);
        }
        public function get pendingName():String{
            return (this.m_data["pendingName"]);
        }
        public function get requiredCount():String{
            return (this.m_data["requiredCount"]);
        }
        public function get requiredMax():String{
            return (this.m_data["requiredMax"]);
        }
        public function get requiredCost():String{
            return (this.m_data["requiredCost"]);
        }
        public function setGridListCellStatus(_arg1:GridList, _arg2:Boolean, _arg3:int):void{
            this.m_bgAsset = (new (this.m_assetDict["cell_bg"])() as DisplayObject);
            this.initBackground();
            ASwingHelper.prepare(_arg1, this.m_headerPanel, this.m_footerPanel);
            this.setPreferredWidth(_arg1.getTileWidth());
            this.setPreferredHeight(_arg1.getTileHeight());
            dispatchEvent(new Event(EVENT_UPDATE));
            ASwingHelper.prepare(this);
        }
        public function setCellValue(_arg1):void{
            this.m_data = _arg1;
            this.m_state = _arg1["state"];
            switch (this.m_state){
                case STATE_PROPOSE:
                    this.m_bodyTextHeading = this.itemName;
                    this.m_bodyTextSubHeading = ZLoc.t("Dialogs", "RenameUI_cellPropose_subHeading");
                    break;
                case STATE_REQUEST:
                    this.m_bodyTextHeading = this.pendingName;
                    this.m_bodyTextSubHeading = ZLoc.t("Dialogs", "RenameUI_cellRequest_subHeading", {oldName:this.itemName.toUpperCase()});
                    break;
                case STATE_FINISH:
                    this.m_bodyTextHeading = this.pendingName;
                    this.m_bodyTextSubHeading = ZLoc.t("Dialogs", "RenameUI_cellFinish_subHeading");
                    break;
            };
            this.buildCell();
        }
        public function getCellValue(){
            return (this.m_data);
        }
        public function getCellComponent():Component{
            return (this);
        }
        protected function setCellText():void{
        }
        protected function buildCell():void{
            this.m_headerPanel = this.createHeaderPanel();
            this.m_bodyPanel = this.createBodyPanel();
            this.m_footerPanel = this.createFooterPanel();
            var _local1:int = Math.max((this.m_headerPanel.getHeight() - 20), this.m_bodyPanel.getHeight(), this.m_footerPanel.getHeight());
            this.m_headerPanel.setPreferredHeight(_local1);
            this.m_bodyPanel.setPreferredHeight(_local1);
            this.m_footerPanel.setPreferredHeight(_local1);
            this.initBackground();
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            _local2.appendAll(this.m_headerPanel, ASwingHelper.horizontalStrut(10), this.m_bodyPanel);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.RIGHT);
            _local3.appendAll(this.m_footerPanel, ASwingHelper.horizontalStrut(10));
            this.append(_local2, BorderLayout.WEST);
            this.append(_local3, BorderLayout.EAST);
        }
        protected function initBackground():void{
            if (this.m_bgAsset){
                this.setBackgroundDecorator(new AssetBackground(this.m_bgAsset));
            };
        }
        protected function createHeaderPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            if (this.item != FranchiseManager.CITY_ITEM_NAME){
                _local1.append(this.createMarketCellPanel());
            };
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function createMarketCellPanel():JPanel{
            var _local1:MarketCell = new MarketCell();
            var _local2:Item = Global.gameSettings.getItemByName(this.item);
            _local1.setAssetDict(this.m_assetDict);
            _local1.setCellValue(_local2);
            _local1.setBuyable(false);
            return (_local1);
        }
        protected function createBodyPanel():JPanel{
            var _local2:JLabel;
            var _local3:JLabel;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            if (this.m_bodyTextHeading != ""){
                _local2 = ASwingHelper.makeLabel(this.m_bodyTextHeading.toUpperCase(), EmbeddedArt.TITLE_FONT, 22, EmbeddedArt.darkBlueTextColor, JLabel.LEFT);
                _local2.setFont(new ASFont(EmbeddedArt.SYSTEM_FONT, 22, true, false, false, new ASFontAdvProperties(false, AntiAliasType.ADVANCED, GridFitType.PIXEL)));
                _local1.append(_local2);
            };
            if (this.m_bodyTextSubHeading != ""){
                _local3 = ASwingHelper.makeLabel(this.m_bodyTextSubHeading, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 18, EmbeddedArt.blueTextColor, JLabel.LEFT);
                _local1.append(_local3);
            };
            _local1.append(this.createSignatureStatusPanel());
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function isProposeEnabled():Boolean{
            var _local1:Boolean;
            if (this.item == FranchiseManager.CITY_ITEM_NAME){
                return (Global.player.hasSetCityName());
            };
            return (_local1);
        }
        protected function createFooterPanel():JPanel{
            var _local2:String;
            var _local3:String;
            var _local4:String;
            var _local5:Boolean;
            var _local6:Boolean;
            var _local7:Function;
            var _local8:Function;
            var _local10:AssetIcon;
            var _local11:CustomButton;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
            switch (this.m_state){
                case STATE_PROPOSE:
                    _local2 = ZLoc.t("Dialogs", "RenameUI_cellPropose_btnRename");
                    _local3 = "OrangeButtonUI";
                    _local7 = this.onProposeClick;
                    _local5 = this.isProposeEnabled();
                    break;
                case STATE_REQUEST:
                    _local2 = ZLoc.t("Dialogs", "RenameUI_cellRequest_btnPostFeed");
                    _local3 = "OrangeButtonUI";
                    _local4 = ZLoc.t("Dialogs", "RenameUI_cellRequest_btnPurchase", {cost:this.requiredCost});
                    _local7 = this.onRequestClick;
                    _local8 = this.onPurchaseClick;
                    _local5 = true;
                    _local6 = true;
                    break;
                case STATE_FINISH:
                    _local2 = ZLoc.t("Dialogs", "RenameUI_cellFinish_btnFinish");
                    _local3 = "GreenButtonUI";
                    _local7 = this.onFinishClick;
                    _local5 = true;
                    break;
            };
            var _local9:CustomButton = new CustomButton(_local2.toUpperCase(), null, _local3);
            if (this.m_state == STATE_REQUEST){
                _local9.setEnabled(Global.world.viralMgr.canPost("request_signature"));
            } else {
                _local9.setEnabled(_local5);
            };
            _local9.addEventListener(MouseEvent.CLICK, _local7);
            _local9.setFont(new ASFont(EmbeddedArt.TITLE_FONT, 14, true, false, false, EmbeddedArt.advancedFontProps));
            _local1.append(_local9);
            if (_local4){
                _local1.append(ASwingHelper.verticalStrut(5));
                _local10 = new AssetIcon((new (this.m_assetDict["pic_cashBtn"])() as DisplayObject));
                _local11 = new CustomButton(_local4.toUpperCase(), _local10, "BigCashButtonUI");
                _local11.setEnabled(_local6);
                _local11.addEventListener(MouseEvent.CLICK, _local8);
                _local11.setFont(new ASFont(EmbeddedArt.TITLE_FONT, 14, true, false, false, EmbeddedArt.advancedFontProps));
                _local1.append(_local11);
            };
            _local1.append(ASwingHelper.verticalStrut(5));
            _local1.setMinimumWidth(BUTTON_WIDTH);
            _local1.setPreferredWidth(BUTTON_WIDTH);
            _local1.setMaximumWidth(BUTTON_WIDTH);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function createSignatureStatusPanel():JPanel{
            var _local2:JLabel;
            var _local3:JLabel;
            var _local4:JLabel;
            var _local5:AssetPane;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            switch (this.m_state){
                case STATE_PROPOSE:
                    _local2 = ASwingHelper.makeLabel(this.requiredMax, EmbeddedArt.TITLE_FONT, 20, EmbeddedArt.orangeTextColor, JLabel.BOTTOM);
                    _local3 = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "RenameUI_cellPropose_footer").toUpperCase(), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.darkBrownTextColor);
                    _local1.appendAll(_local2, _local3);
                    break;
                case STATE_REQUEST:
                    _local2 = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "RenameUI_cellRequest_footer1", {
                        count:this.requiredCount,
                        max:this.requiredMax
                    }), EmbeddedArt.TITLE_FONT, 20, EmbeddedArt.orangeTextColor);
                    _local3 = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "RenameUI_cellRequest_footer2").toUpperCase(), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.darkBrownTextColor);
                    _local1.appendAll(_local2, _local3);
                    break;
                case STATE_FINISH:
                    _local5 = new AssetPane((new (this.m_assetDict["pic_checkGreen"])() as DisplayObject));
                    _local2 = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "RenameUI_cellFinish_footer").toUpperCase(), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.darkBrownTextColor);
                    _local1.appendAll(_local5, _local2);
            };
            return (_local1);
        }
        protected function onProposeClick(_arg1:Event):void{
            dispatchEvent(new RenameEvent(RenameEvent.PROPOSE_CLICK, this.item, true, true));
        }
        protected function onRequestClick(_arg1:Event):void{
            dispatchEvent(new RenameEvent(RenameEvent.REQUEST_CLICK, this.item, true, true));
        }
        protected function onPurchaseClick(_arg1:Event):void{
            dispatchEvent(new RenameEvent(RenameEvent.PURCHASE_CLICK, this.item, true, true));
        }
        protected function onFinishClick(_arg1:Event):void{
            dispatchEvent(new RenameEvent(RenameEvent.FINISH_CLICK, this.item, true, true));
        }

    }
}//package Display.RenameUI 
